package com.anyou.mall.help.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.anyou.common.annotation.Log;
import com.anyou.common.core.controller.BaseController;
import com.anyou.common.core.domain.ApiResult;
import com.anyou.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.anyou.mall.help.domain.HelpDocument;
import com.anyou.mall.help.service.IHelpDocumentService;
import com.anyou.common.utils.poi.ExcelUtil;
import com.anyou.common.core.page.TableDataInfo;

/**
 * 常见故障分析Controller
 *
 * @author xq
 * @date 2022-04-09
 */
@Api(tags = "常见故障分析")
@RestController
@RequestMapping("/help/faultAnalyse")
public class HelpDocumentController4 extends BaseController
{
    @Autowired
    private IHelpDocumentService helpDocumentService;

    /**
     * 查询常见故障分析列表
     */
    @ApiOperation("查询常见故障分析列表(需要传文档类型)")
    @PreAuthorize("@ss.hasPermi('help:faultAnalyse:list')")
    @GetMapping("/list")
    public TableDataInfo<List<HelpDocument>> list(HelpDocument helpDocument)
    {
        startPage();
        List<HelpDocument> list = helpDocumentService.selectHelpDocumentList(helpDocument);
        return getDataTable(list);
    }

    /**
     * 导出常见故障分析列表
     */
    @ApiOperation("导出常见故障分析列表")
    @PreAuthorize("@ss.hasPermi('help:faultAnalyse:export')")
    @Log(title = "常见故障分析", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HelpDocument helpDocument)
    {
        List<HelpDocument> list = helpDocumentService.selectHelpDocumentList(helpDocument);
        ExcelUtil<HelpDocument> util = new ExcelUtil<HelpDocument>(HelpDocument.class);
        util.exportExcel(response, list, "常见故障分析数据");
    }

    /**
     * 获取常见故障分析详细信息
     */
    @ApiOperation("获取常见故障分析详细信息")
    @PreAuthorize("@ss.hasPermi('help:faultAnalyse:query')")
    @GetMapping(value = "/{docId}")
    public ApiResult<HelpDocument> getInfo(@PathVariable("docId") Long docId)
    {
        return ApiResult.success(helpDocumentService.selectHelpDocumentByDocId(docId));
    }

    /**
     * 新增常见故障分析
     */
    @ApiOperation("新增常见故障分析(需要传文档类型)")
    @PreAuthorize("@ss.hasPermi('help:faultAnalyse:add')")
    @Log(title = "常见故障分析", businessType = BusinessType.INSERT)
    @PostMapping
    public ApiResult add(@RequestBody HelpDocument helpDocument)
    {
        return ApiResult.success(helpDocumentService.insertHelpDocument(helpDocument));
    }

    /**
     * 修改常见故障分析
     */
    @ApiOperation("修改常见故障分析")
    @PreAuthorize("@ss.hasPermi('help:faultAnalyse:edit')")
    @Log(title = "常见故障分析", businessType = BusinessType.UPDATE)
    @PutMapping
    public ApiResult edit(@RequestBody HelpDocument helpDocument)
    {
        return ApiResult.success(helpDocumentService.updateHelpDocument(helpDocument));
    }

    /**
     * 删除常见故障分析
     */
    @ApiOperation("删除常见故障分析")
    @PreAuthorize("@ss.hasPermi('help:faultAnalyse:remove')")
    @Log(title = "常见故障分析", businessType = BusinessType.DELETE)
    @DeleteMapping("/{docIds}")
    public ApiResult remove(@PathVariable Long[] docIds)
    {
        return ApiResult.success(helpDocumentService.deleteHelpDocumentByDocIds(docIds));
    }
}
